package com.wanli.graalvmdemo.controller;

import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

@RestController
@RequestMapping("/auth")
public class AuthController {

    @GetMapping("/login")
    public String login() {
        return "Please login with username and password";
    }

    @GetMapping("/test")
    public String testAuthenticated() {
        return "Authenticated successfully!";
    }

    /**
     * 无效
     */
    @Secured({"ROLE_ADMIN"})
    @RequestMapping(value = "/test1")
    public Mono<String> test() {
        return Mono.just("test1");
    }

    /**
     * 有效
     */
    @PreAuthorize("hasRole('ADMIN')")
    @RequestMapping(value = "/test2")
    public Mono<String> test1() {
        return Mono.just("test2");
    }

    @Secured({"ROLE_TEST"})
    @RequestMapping(value = "/test3")
    public Mono<String> test2() {
        return Mono.just("test3");
    }
}